import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
// 先把页面文件导入进来
import Work1 from '../views/Work1.vue';
import Work2 from '../views/Work2.vue';
import Work3 from '../views/Work3.vue';
import Random from '../views/Random.vue';
import Book from '../views/Book.vue';
import BookShop from '../views/BookShop.vue';
import Basket from '../views/basket/Index.vue';
import Life from '../views/Life.vue';
import Admin from '../views/admin/Index.vue';
import Main from '../views/admax/Main.vue';
import List from '../views/admax/List.vue';
import Detail from '../views/admax/Detail.vue';
import StockList from '../views/stock/List.vue';
import StockDetail from '../views/stock/Detail.vue';
//安装
Vue.use(VueRouter)
// 定义路由(访问一个路径能看到一个不同页面)页面
const routes = [
  {
    path:'/stock/list',
    component:StockList,
    children:[
      {
        // path:'detail/:id'
        path:':id',
        component:StockDetail
      }
    ]
  },
  //一级路由
  {
    path:'/main',
    component:Main,
    //给Main页面组件定义子路由
    //子路由/嵌套路由的路径path前不需要加‘/’
    //redirect 访问一个路径跳转另一个路径
    children:[
      {
        path:'',
        redirect:'list'
      },
      {
        path:'list',
        component:List
      },
      {
        path:'detail',
        component:Detail
      }
    ]
  },
  {
    path:'/life-box',
    component:()=>import('../views/LifeBox.vue')
  },
  // {
  //   path:'/element',
  //   component:()=>import('../views/Element.vue')
  // },
  {
    path:'/v-model',
    component:()=>import('../views/VModel.vue')
  },
  {
    path:'/album-list',
    component:()=>import('../views/AlbumList.vue')
  },
  {
    path:'/pull-refresh',
    component:()=>import('../views/PullRefresh.vue')
  },
  // 异步路由,文件会单独打包,当访问这个路由的时候才加载对应的文件;首屏渲染速度,webpack所支持的语法
  {
    path:'/component',
    component:()=>import('../views/Component.vue')
  },
  {
    path:'/scroll-load',
    component:()=>import('../views/ScrollLoad.vue')
  },
  {
    path:'/watch',
    component:()=>import('../views/Watch.vue')
  },
  {
    path:'/computed',
    component:()=>import('../views/Computed.vue')
  },
  {
    path:'/slider',
    component:()=>import('../views/Slider.vue')
  },
  {
    path:'/validate',
    component:()=>import('../views/Validate.vue')
  },
  {
    path:'/form',
    component:()=>import('../views/Form.vue')
  },
  {
    path:'/contextmenu',
    component:()=>import('../views/Contextmenu.vue')
  },
  {
    path:'/event',
    component:()=>import('../views/Event.vue')
  },
  {
    path:'/weread',
    component:()=>import('../views/WeRead.vue')
  },
  {
    path:'/transition',
    component:()=>import('../views/Transition.vue')
  },
  //路由,路径path和页面组件component的对应关系
  {
    path:'/tabs',//当访问这个路径的时候 会将这个组件展示出来
    component:()=>import('../views/Tabs.vue')
  },
  {
    path:'/api',
    component:()=>import('../views/API.vue')
  },
  {
    path:'/administrator',
    redirect:'/admin/work-1'
  },
  {
    path:'/work-1',//访问路径(#后面的路径)
    component:Work1//对应的页面组件
  },
  {
    path:'/life',//访问路径(#后面的路径)
    component:Life//对应的页面组件
  },
  {
    path:'/work-3',//访问路径(#后面的路径)
    component:Work3//对应的页面组件
  },
  {
    path:'/basket',//访问路径(#后面的路径)
    component:Basket//对应的页面组件
  },
  {
    path:'/book',//访问路径(#后面的路径)
    component:Book//对应的页面组件
  },
  {
    path:'/book-shop',//访问路径(#后面的路径)
    component:BookShop//对应的页面组件
  },
    {
      path:'/work-2',//访问路径(#后面的路径)
      component:Work2//对应的页面组件
    },
  {
    path:'/random',//访问路径(#后面的路径)
    component:Random//对应的页面组件
  },
  {
    path:'/admin',//访问路径(#后面的路径)
    component:Admin,//对应的页面组件
    // 子路由 二级路由 嵌套路由
    children:[{
      //子路由路径不需要加前面的斜杠/
      path:'work-1',
      component:Work1
    },{
      path:'work-2',
      component:Work2
    }]
  },
  {
    path:'/page-1',//访问路径(#后面的路径)
    component:()=>import('../views/Page1.vue')//对应的页面组件  异步路由 打包单独文件
  },
  {
    path:'/page-2',//访问路径(#后面的路径)
    component:()=>import('../views/Page2.vue')//对应的页面组件
  },
  //动态路径 带冒号的部分可以传递变量
  {
    path:'/page-3/:id/:type',//访问路径(#后面的路径)
    component:()=>import('../views/Page3.vue')//对应的页面组件
  },
  {
    path:'/wishlist/index',//访问路径(#后面的路径)
    component:()=>import('../views/Wishlist.vue')//对应的页面组件
  },
  {
    path: '/home',
    name: 'Home',
    component: Home
  },
  //路由跳转 重定向
  {
    path:'/',
    redirect:'/home'
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    // /* webpackChunkName: "about" */ 打包文件
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path:'/image',
    component:()=>import('../views/Image.vue')
  }
]
// 创建路由实例,整个vue项目中只有一个router实例
const router = new VueRouter({
  routes
})
// const isCook  =false
// router.beforeEach((to,from,next)=>{
//   console.log(to,from);
//   if(to.path==='/basket'){
//     if(isCook){
//       next();
//     }else {
//       next('/')
//     }
//   }
// })
export default router
